﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using cn.sharesdk.unity3d;

public class PDKReplace : MonoBehaviour {
    EginPDK pdk = EginPDK.Instance;
    EginDDZ ddz = EginDDZ.Instance;
    EginDN dn = EginDN.Instance;
    public GameObject copyBtn;
    public GameObject shareBtn;
    public GameObject closeBtn;
    public UILabel roomIdLabel;
    public UILabel topLabel;
    public GameObject goldPattern;
    public GameObject cardPattern;
    //房卡模式创建内容
    public UILabel cardContent;
    //金币模式创建内容
    public UILabel goldContent1;
    public UILabel goldContent2;

    private ShareSDK ssdk;

    void Awake()
    {
        ssdk = GameObject.Find("SoundManger").GetComponent<ShareSDK>(); 
        ssdk.shareHandler = OnShareResultHandler;
      
        UIEventListener.Get(copyBtn).onClick = ButtonClick;
        UIEventListener.Get(shareBtn).onClick = ButtonClick;
        UIEventListener.Get(closeBtn).onClick = ButtonClick;
  
    }

    void Start()
    {
        //if(goldPattern.activeSelf == true){
            //if(EginUser.Instance.gameType == 4)
            //{
            //    topLabel.text = "跑得快房间（金币模式）创建成功！";
            //    goldContent1.text = EginUser.Instance.ReturnRelCoinForBrief(pdk.baseScore);
            //    goldContent2.text = pdk.totalRound + "局";
            //    roomIdLabel.text = pdk.roomId.ToString();
            //}
            //else if (EginUser.Instance.gameType == 3)
            //{
            //    topLabel.text = "斗地主房间（金币模式）创建成功！";
            //    goldContent1.text = EginUser.Instance.ReturnRelCoinForBrief(ddz.baseScore);
            //    goldContent2.text = ddz.totalRound + "局";
            //    roomIdLabel.text = ddz.roomId.ToString();
            //}
            //else if (EginUser.Instance.gameType == 2)
            //{
            //    topLabel.text = "斗牛房间（金币模式）创建成功！";
            //    goldContent1.text = EginUser.Instance.ReturnRelCoinForBrief(dn.baseScore);
            //    goldContent2.text = dn.totalRound + "局";
            //    roomIdLabel.text = dn.roomId.ToString();
            //}                     
        //}
        //else if (cardPattern.activeSelf == true)
        //{
            //if (EginUser.Instance.gameType == 4)
            //{
            //    topLabel.text = "跑得快房间（房卡模式）创建成功！";
            //    cardContent.text = pdk.totalRound + "局";
            //    roomIdLabel.text = pdk.roomId.ToString();
            //}
            //else if (EginUser.Instance.gameType == 3)
            //{
            //    topLabel.text = "斗地主房间（房卡模式）创建成功！";
            //    cardContent.text = ddz.totalRound + "局";
            //    roomIdLabel.text = ddz.roomId.ToString();
            //}
            //else if (EginUser.Instance.gameType == 2)
            //{
            //    topLabel.text = "斗牛房间（房卡模式）创建成功！";
            //    cardContent.text = dn.totalRound + "局";
            //    roomIdLabel.text = dn.roomId.ToString();
            //}              
        //}

        
    }

    void ButtonClick(GameObject button)
    {
        if (button.name == "CopyRoomIdBtn")
        {
            UniPasteBoard.SetClipBoardString(roomIdLabel.text); 
        }
        else if (button.name == "ShareBtn")
        {

            Debug.Log("分享给微信好友");
            ShareContent content = new ShareContent();
            string downloadUrl = GameObject.Find("UI Root/HallPanel").GetComponent<HallModel>().downloadUrl;
            content.SetText("快来和我一起游戏吧！房间号："  + roomIdLabel.text);
            //content.SetImageUrl("https://f1.webshare.mob.com/code/demo/img/1.jpg");
            content.SetTitle("欢乐掌上棋牌");
            //content.SetTitleUrl("http://www.mob.com");
            content.SetSite("Mob-ShareSDK");
            content.SetSiteUrl("http://www.mob.com");
            content.SetUrl(downloadUrl);
            content.SetComment("欢乐嗨翻天！");
            //content.SetMusicUrl("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3");
            content.SetShareType(ContentType.Text);
            ssdk.ShareContent(PlatformType.WeChat, content);

        }
        else if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }

    void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
    {
        if (state == ResponseState.Success)
        {
            print("share successfully - share result :");
            print(MiniJSON.jsonEncode(result));
        }
        else if (state == ResponseState.Fail)
        {
#if UNITY_ANDROID
            print("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
#elif UNITY_IPHONE
			print ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
#endif
        }
        else if (state == ResponseState.Cancel)
        {
            print("cancel !");
        }
    }

}
